<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>原型链-属性问题</title>
</head>
<body>

<!-- 
    1. 读取对象的属性时：会自动到原型对象链中查找
    2. 设置对象的属性值时：不会查找原型链，如果当前对象中没有此属性，直接添加此属性并设置其值
    3. 方法一般定义在原型中，属性一般通过构造函数定义在对象本身上
 -->

<script type="text/javascript">

    function Fn(){

    }
    Fn.prototype.a = 'xxx'

    var fn1 = new Fn()
    console.log(fn1.a)
    
    var fn2 = new Fn()
    // console.log(fn2.a)
    fn2.a = 'yyy'
    console.log(fn1.a, fn2.a)

    fn2.__proto__.a = 'ccc'
    console.log(fn1.a, fn2.a)


    function Person(name,age){
        this.name = name 
        this.age = age

    }
    Person.prototype.sayName = function(name){
        this.name = name
    }

    var p1 = new Person('Tom',18)
    p1.sayName('jery')
    console.log(p1)
</script>
</body>
</html>